package cn.page;


import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*
 * 生成验证码
 * 1.生成图片
 * 2.保存图片
 * 3.响应图片
 */
public class VeifyCodeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
  
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		VerifyCode vf=new VerifyCode();
		BufferedImage bi=vf.getImage();
		
		//将图片内容保存在session域中
		request.getSession().setAttribute("vcode", vf.getText());
		//用VC的输出流将图片输出，response响应到页面上
		VerifyCode.output(bi, response.getOutputStream());
	}

}